﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BLL;
using BO;

public partial class Pages_Dashboard_Account : System.Web.UI.Page, ICrumbedPage
{
	public int AccountID
	{
		get
		{
			int temp;
			int.TryParse(Request["ID"], out temp);
			return temp;
		}
	}
	protected BO.User User;
	protected BO.Account Account;

	private void Authenicate()
	{
		if (Authentication.IsCurrentUserAuthenticated())
			User = Authentication.GetCurrentUser();

		if (User == null)
			Response.Redirect("/default.aspx");
	}

	protected void Page_Load(object sender, EventArgs e)
	{
		Authenicate();
		Account = Account.GetWithMaster(AccountID);
		fanOverview.Account = Account;
		if (!IsPostBack)
			LoadData();
	}

	private void LoadData()
	{			
		if (!Logic.BusinessLogic.AccountService.IsUserAutorisedForAccount(User,Account.MasterAccount))
			Response.Redirect("/default.aspx");

		ltrName.Text = TailName = Account.Name;
        ucAccountSideMenu.AccountID = AccountID;
		postOverview.OverView = Logic.BusinessLogic.Stats.GetPostsOverview(Account.ID);
		LoadRecenPosts();
	}

	private void LoadRecenPosts()
	{
		
			var posts = Logic.BusinessLogic.Stats.GetPostsByAccountID(Account.ID,count:5);
			repPosts.DataSource = posts;
			repPosts.DataBind();
	}



	#region ICrumbedPage Members

	public int Level
	{
		get { return 3; }
	}

	public string TailName { get; set; }
	

	#endregion
}